//var url1="http://127.0.0.1:5000";
var url1="http://123.207.117.96:5001";
(function(angular) {
	angular.module('myapp')
		.controller('homeCtrl', function($scope, $http, $state, $window) {
			　console.log(window.location)
			var uri="http://123.207.117.96:5001/"
			var getUserInfo = function() {
				$http({
					method: 'GET',
					url: uri+"userinfo?token="+$scope.access_token+"&openid="+$scope.openid,
					header: 'Content-Type:application/json'
				}).success(function(data, status) {
					console.log(data)
					$scope.userinfo=data;
				}).error(function() {
					console.log("err");
				});
			}
			
			
			var getOpenid = function(token) {
				$http({
					method: 'GET',
					url: uri+"qqOpen?token="+token,
					header: 'Content-Type:application/json'
				}).success(function(data, status) {
					console.log(data)
					$scope.openid=data
					getUserInfo();
				}).error(function() {
					console.log("err");
				});
			}
			var getAccess_Token = function(code) {
				$http({
					method: 'GET',
					url: uri+"qqAccessToken?code="+code,
					header: 'Content-Type:application/json'
				}).success(function(data, status) {
					console.log(data)
					$scope.access_token=data
					getOpenid(data)
				}).error(function() {
					console.log("err");
				});
			}
			
			$scope.authOperate=false;
			if(window.location.search){
				$scope.authOperate=true;
				$scope.authCode=window.location.search.substr(6);
				getAccess_Token($scope.authCode)
				console.log($scope.authCode)
				
			}else{
				$scope.authOperate=false;
				
			}

			$scope.getauth = function() {
				$http({
					method: 'GET',
					url: uri+"qqAuthCode",
					header: 'Content-Type:application/json'
				}).success(function(data, status) {
					window.location.href=data
				}).error(function() {
					console.log("err");
				});
			}
		    
			
		})
})(angular);